package com.mystudy.management.usermanagement.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class ControllerLog implements SystemAspect {

    @Pointcut("execution(public * com.mystudy.management.usermanagement.controller.*.*(..))")
    public void pointCut(){}

    @Override
    @Before("pointCut()")
    public void beforeExcLog(JoinPoint joinPoint) {
        System.out.println("[Controller] "+joinPoint.getSignature().getName()+" ready to execute");
    }

    @Override
    public void afterExcLog(JoinPoint joinPoint) {

    }

    @Override
    @AfterReturning("pointCut()")
    public void afterExcSucLog(JoinPoint joinPoint) throws Throwable {
        System.out.println("[Controller] "+joinPoint.getSignature().getName()+" execute successfully");
    }

    @Override
    @AfterThrowing(value = "pointCut()",throwing = "e")
    public void errorExcLog(JoinPoint joinPoint, Exception e) {
        System.out.println("[Controller]"+joinPoint.getSignature().getName()+" error，errorLog--"+e.getMessage());
    }
}
